﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using lbl.WcfServices.Services;

namespace WindowsServiceHosting
{
    public partial class Calculator : ServiceBase
    {
        ServiceHost host;
        public Calculator()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            using (host = new ServiceHost(typeof(CalculatorService)))
            {
                //host.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "http://127.0.0.1:9999/calculatorservice");
                //if (host.Description.Behaviors.Find<ServiceMetadataBehavior>()==null)
                //{
                //    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                //    behavior.HttpGetEnabled = true;
                //    behavior.HttpGetUrl = new Uri("http://127.0.0.1:9999/calculatorservice/metadata");
                //    host.Description.Behaviors.Add(behavior);
                //}
                host.Opened += delegate
                {
                    Console.WriteLine("CalculaorService已经启动，按任意键终止服务！");
                };

                host.Open();
                Console.Read();
            }
        }

        protected override void OnStop()
        {
            if (host != null)
            {
                host.Close();
                host = null;
            }
        }
    }
}
